#!/usr/bin/env bash

if [ $UID -ne 0 ]; then
    echo "Superuser privileges are required to run this script."
    echo "e.g. \"sudo $0\""
    exit 1
fi

docker run --name consul_dev -d --restart=always -p 8500:8500 consul

#server-1
echo "start consul server 1"
docker run -d -p 8500:8500 --restart=always docker run --net=host --name consul_server_1 -v /opt/consul/data/:/consul/data -v /opt/consul/conf:/consul/config consul agent -server -bootstrap-expect=3 -ui -node=consult_server_1 -client='0.0.0.0' -data-dir /consult/data -config-dir /consul/config -datacenter=dc1


#server-2
echo "start consul server 2"
docker run -d -p 8501:8500 --restart=always docker run --net=host --name consul_server_2 -v /opt/consul/data/:/consul/data -v /opt/consul/conf:/consul/config consul agent -server -bootstrap-expect=3 -ui -node=consult_server_2 -client='0.0.0.0' -data-dir /consult/data -config-dir /consul/config -datacenter=dc1

#server-3
echo "start consul server 3"
docker run -d -p 8501:8500 --restart=always docker run --net=host --name consul_server_3 -v /opt/consul/data/:/consul/data -v /opt/consul/conf:/consul/config consul agent -server -bootstrap-expect=3 -ui -node=consult_server_3 -client='0.0.0.0' -data-dir /consult/data -config-dir /consul/config -datacenter=dc1



docker run -d -p 8500:8500 --restart=always -e CONSUL_BIND_INTERFACE='eth0' --name=consul_server_1 consul agent -server -bootstrap-expect=3 -ui -node=consul_server_1 -client='0.0.0.0'

docker run -d -p 8500:8500 --restart=always -e CONSUL_BIND_INTERFACE='eth0' --name=consul_server_1 consul agent -server -ui -node=consul_server_1 -client='0.0.0.0'

consulServer1=`docker inspect -f '{{.NetworkSettings.IPAddress}}' consul_server_1`

docker run -d -p 8501:8500 --restart=always -e CONSUL_BIND_INTERFACE='eth0' --name=consul_server_2 consul agent -server -ui -node=consul_server_2 -client='0.0.0.0' -retry-join='172.17.0.2'

docker run -d -p 8502:8500 --restart=always -e CONSUL_BIND_INTERFACE='eth0' --name=consul_server_3 consul agent -server -ui -node=consul_server_3 -client='0.0.0.0' -retry-join='172.17.0.2'

docker run -d -p 8503:8500 --restart=always -e CONSUL_BIND_INTERFACE='eth0' --name=consul_client_1 consul agent -ui -node=consul_client_1 -client='0.0.0.0' -retry-join='172.17.0.2'

docker run -d -p 8500:8500 --net=host --name=consul_server_1 consul agent -server -ui -node=consul_server_1 -bind='172.16.208.89' -client='0.0.0.0'

docker run -d -p 8502:8500 -e CONSUL_BIND_INTERFACE='eth0' --name=consul_server_2 consul agent -server -ui -node=consul_server_2 -client='0.0.0.0' -join='172.17.0.2'

#rabbitmq
docker run -d --restart=always --network egift --network-alias rabbitmq --name=rabbitmq -e RABBITMQ_DEFAULT_USER='admin' -e RABBITMQ_DEFAULT_PASS='root123' -p 15672:15672 -p 5672:5672 rabbitmq:3.7.27-management

docker run -d --name=rabbitmq -e RABBITMQ_DEFAULT_USER='admin' -e RABBITMQ_DEFAULT_PASS='root123' -p 15672:15672 -p 5672:5672 rabbitmq:3.7.27-management

sudo docker run -d -p 8001:8001 -e SERVER_PORT='8001' --name=demo-config-8001 org.elanfox.demo/demo-config

sudo docker run -d -p 8401:8401 -e SERVER_PORT='8401' --name=demo-user-8401 org.elanfox.demo/demo-user

sudo docker run -d -p 8400:8400 -e SERVER_PORT='8400' --name=demo-user-8400 org.elanfox.demo/demo-user

docker run -d -p 8500:8500 --restart=always -e CONSUL_BIND_INTERFACE='eth0' --name=consul_server_1 consul agent -server -bootstrap-expect=3 -ui -node=consul_server_1 -client='0.0.0.0'

#xxl-job
docker run -d -e PARAMS="--spring.datasource.url=jdbc:mysql://host.docker.internal:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai --spring.datasource.username=root --spring.datasource.password=root123" -p 8070:8080 --name xxl-job-admin xuxueli/xxl-job-admin:2.3.0

docker run -d --restart=always --name mysql -p 3306:3306 -v /data1/mysql:/etc/mysql -e MYSQL_ROOT_PASSWORD=root123 mysql:5.7.37

#nexus
docker run -d --restart=always -u root --privileged=true -p 8091:8081 --name nexus -v /data/nexus-data:/nexus-data sonatype/nexus3:3.29.2

#activeMq
docker run -d --name=activeMq --restart=always -p 8071:8161 -p 61616:61616 -e ACTIVEMQ_ADMIN_LOGIN=admin -e ACTIVEMQ_ADMIN_PASSWORD=root123 -v /data1/middleware/activemq:/data/activemq -v /data1/middleware/activemq/log:/var/log/activemq webcenter/activemq


#nacos
docker run -d --name=nacos --restart=always -p 8072:8848 --network egift --network-alias nacos -e MODE=standalone nacos/nacos-server


#mysql slave
docker run -d --name=mysql-base --network mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --network-alias mysql-master mysql
docker run -d --name=mysql-master --network mysql -v /Users/Allan/Develop/Deploys/Mysql:/etc/mysql/conf.d -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --network-alias mysql-master mysql
docker run -d --name=mysql-slave --network mysql -v /Users/Allan/Develop/Deploys/Mysql/slave:/etc/mysql/conf.d -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --network-alias mysql-slave mysql
grant replication slave on *.* to 'masterbackup'@'172.18.0.4' IDENTIFIED BY '123456';

grant replication slave on *.* to 'masterback'@'172.18.0.4' IDENTIFIED BY 'root123';

change master to master_host='172.18.0.2',master_port=3306,master_user='masterback',master_password='root123',master_log_file='master-bin.000003',master_log_pos=156


#redis
docker run -d --name=redis --restart=always -p 8070:6379 --network egift --network-alias redis -v /data1/middleware/redis/redis.conf:/etc/redis/redis.conf redis:5.0.9 redis-server /etc/redis/redis.conf
docker run -d --name=redis --restart=always -p 6379:6379 redis:6.2.14 --requirepass "dIw32w-8xo1co-tytdkx"
docker run -d --name=redis --restart=always -p 6379:6379 --network asiabuy --network-alias redis redis:6.2.14 --requirepass "dIw32w-8xo1co-tytdkx"

docker run -d --name=redis --restart=always -p 6379:6379 -v /opt/redis/redis.conf:/etc/redis/redis.conf redis:5.0.9 redis-server /etc/redis/redis.conf
docker run -d --name=redis-6381 --restart=always -p 6381:6379 -v /opt/redis/redis.conf:/etc/redis/redis.conf redis:5.0.9 redis-server /etc/redis/redis.conf

docker run -d --name=redis --restart=always -p 6379:6379 -v /opt/redis/redis.conf:/etc/redis/redis.conf -v /opt/redis/redis.log:/etc/redis/redis.log redis:5.0.9 redis-server /etc/redis/redis.conf

docker run -d --name=redis --restart=always -p 6379:6379 -v /opt/redis/redis.conf:/etc/redis/redis.conf redis:5.0.9 redis-server /etc/redis/redis.conf

docker run -d --name=redis -p 6379:6379 -v /Users/Allan/Develop/Deploys/Redis/redis.conf:/etc/redis/redis.conf redis:5.0.9 redis-server /etc/redis/redis.conf

docker run -d --name=redis --restart=always -p 6379:6379 redis:5.0.9 redis-server /etc/redis/redis.conf --appendonly yes #--appendonly yes 持久化


docker run -d -p 8090:8080 -v /opt/deploy/sport-manager/webapps:/usr/local/tomcat/webapps -v /opt/deploy/sport-manager/logs:/usr/local/tomcat/logs --name sport-manager-8090 --restart=always tomcat

docker run -d -p 8090:8080 -v /opt/deploy/sport-manager/conf/context.xml:/usr/local/tomcat/conf/context.xml -v /opt/deploy/sport-manager/webapps:/usr/local/tomcat/webapps -v /opt/deploy/sport-manager/logs:/usr/local/tomcat/logs --name sport-manager-8090 --restart=always tomcat


docker run -p 3306:3306 -v /opt/mysql/mysql.conf.d/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf -v /opt/mysql/data:/var/lib/mysql --name mysql -e MYSQL_ROOT_PASSWORD=root123 -d mysql:5.7

docker run -d -p 3306:3306 --restart=always -v /data1/mysql/config:/etc/mysql/conf.d -v /data1/mysql/data:/var/lib/mysql -v /data1/mysql/log:/var/log/mysql --name mysql -e MYSQL_ROOT_PASSWORD=monxaj-fypvyq-9codQy mysql:5.7.37

docker run -d -p 3306:3306 --restart=always -v /home/mysql/config:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -v /home/mysql/log:/var/log/mysql --name mysql -e MYSQL_ROOT_PASSWORD=monxaj-fypvyq-9codQy mysql:5.7.41 --skip-name-resolve

docker run -d -p 3306:3306 --restart=always -v /data/mysql/config:/etc/mysql/conf.d -v /data/mysql/data:/var/lib/mysql -v /data/mysql/log:/var/log/mysql --name mysql -e MYSQL_ROOT_PASSWORD=monxaj-fypvyq-9codQy mysql:5.7.41 --skip-name-resolve

#创建docker的网络，允许独立container之间的通信
docker network create --driver bridge bear
docker network create --driver bridge asiabuy

sudo docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7



firewall-cmd --zone=public --add-port=3306/tcp --permanent

firewall-cmd --zone=public --add-port=5672/tcp --permanent

firewall-cmd --zone=public --add-port=6379/tcp --permanent

docker run -d --name=redis --restart=always -p 6379:6379 -v /data1/redis:/etc/redis redis:5.0.9 redis-server /etc/redis/redis.conf

docker run -d -p 8174:8080 --name uc-as-8174 -v /data1/uc-as/webapps:/usr/local/tomcat/webapps -v /data1/uc-as/logs:/usr/local/tomcat/logs -v /data1/uc-as/server.xml:/usr/local/tomcat/conf/server.xml --restart=always tomcat:8.5-jdk8-openjdk


docker run -d -p 8174:8080 --name uc-as-8174 -v /data1/uc-as/webapps:/usr/local/tomcat/webapps -v /data1/uc-as/logs:/usr/local/tomcat/logs -v /data1/uc-as/server.xml:/usr/local/tomcat/conf/server.xml --restart=always tomcat:8.5-jdk8-openjdk

docker run -d -p 8173:8080 --name uc-admin-8173 -v /data1/uc-admin/webapps:/usr/local/tomcat/webapps -v /data1/uc-admin/logs:/usr/local/tomcat/logs -v /data1/uc-admin/server.xml:/usr/local/tomcat/conf/server.xml -v /share:/share --restart=always tomcat:8.5-jdk8-openjdk

docker run -d -p 6075:8080 --name eclp-6075 -v /data1/eclp/webapps:/usr/local/tomcat/webapps -v /data1/eclp/logs:/usr/local/tomcat/logs -v /data1/eclp/server.xml:/usr/local/tomcat/conf/server.xml -v /share:/share --restart=always tomcat:8.5-jdk8-openjdk

docker run -d -p 8115:8080 --name cprs-common -v /data1/cprs_commonservice_admin/webapps:/usr/local/tomcat/webapps -v /data1/cprs_commonservice_admin/logs:/usr/local/tomcat/logs -v /data1/cprs_commonservice_admin/server.xml:/usr/local/tomcat/conf/server.xml -v /share:/share --restart=always tomcat:8.5-jdk8-openjdk

docker run -d -p 8089:8080 --name yyt_web_middle -v /data1/yyt_web_middle/webapps:/usr/local/tomcat/webapps -v /data1/yyt_web_middle/logs:/usr/local/tomcat/logs -v /data1/yyt_web_middle/server.xml:/usr/local/tomcat/conf/server.xml --restart=always tomcat:8.5-jdk8-openjdk

docker run -d -p 8087:8080 --name yyt_admin -v /data1/cprs_yyt_admin/webapps:/usr/local/tomcat/webapps -v /data1/cprs_yyt_admin/logs:/usr/local/tomcat/logs -v /data1/cprs_yyt_admin/server.xml:/usr/local/tomcat/conf/server.xml --restart=always tomcat:8.5-jdk8-openjdk

docker run -d -p 8086:8080 --name cprs_yyt_match -v /data1/cprs_yyt_match/webapps:/usr/local/tomcat/webapps -v /data1/cprs_yyt_match/logs:/usr/local/tomcat/logs -v /data1/cprs_yyt_match/server.xml:/usr/local/tomcat/conf/server.xml --restart=always tomcat:8.5-jdk8-openjdk

docker run -d -p 8064:8080 --name hps-as -v /data1/hps-as/webapps:/usr/local/tomcat/webapps -v /data1/hps-as/logs:/usr/local/tomcat/logs -v /data1/hps-as/server.xml:/usr/local/tomcat/conf/server.xml --restart=always tomcat:8.5-jdk8-openjdk

-v /data1/jres-ar/:/usr/local/tomcat/webapps -v /opt/deploy/sport-manager/logs:/usr/local/tomcat/logs


docker run -d --name=phpadmin --restart=always -p 8095:80  tropicloud/phpadmin

docker run --name phpmyadmin --restart=always -d -e PMA_ARBITRARY=1 -p 8095:80 phpmyadmin

docker run -d --name phpmyadmin --restart=always -e PMA_HOST=database-1.cluster-custom-c1oew8qig7h5.ap-northeast-2.rds.amazonaws.com -e PMA_PORT=3306 -p 8095:80 phpmyadmin



#gitlab


docker run -d -p 8082:80 -p 22:22 -v /opt/gitlab/etc:/etc/gitlab -v /opt/gitlab/log:/var/log/gitlab -v /opt/gitlab/opt:/var/opt/gitlab --restart always --privileged=true --name gitlab gitlab/gitlab-ce:10.0.0-ce.0
# 启动容器
docker run \
 -itd  \
 -p 8090:80 \
 -p 22:22 \
 -v /data/gitlab/etc:/etc/gitlab  \
 -v /data/gitlab/log:/var/log/gitlab \
 -v /data/gitlab/opt:/var/opt/gitlab \
 --restart always \
 --privileged=true \
 --name gitlab \
gitlab/gitlab-ce:10.0.0-ce.0



#rockedmq
#启动namesrv
docker run -d -p 9876:9876 --name rmqnamesrv --restart=always -v /data/rocketmq/namesrv/logs:/root/logs -v /data/rocketmq/namesrv/store:/root/store -e "MAX_POSSIBLE_HEAP=100000000" rocketmqinc/rocketmq sh mqnamesrv

#启动broker
docker run -d -p 10911:10911 -p 10909:10909 --name rmqbroker --restart=always -v /opt/volume/rocketmq/broker/logs:/root/logs -v /opt/volume/rocketmq/broker/store:/root/store -v /opt/volume/rocketmq/broker/conf/broker.conf:/opt/rocketmq-4.4.0/conf/broker.conf --link rmqnamesrv:namesrv -e "NAMESRV_ADDR=namesrv:9876" -e "MAX_POSSIBLE_HEAP=200000000" rocketmqinc/rocketmq:latest sh mqbroker -c /opt/rocketmq-4.4.0/conf/broker.conf

#console
docker run -d -p 8070:8080 --name rmqconsole --restart=always --link rmqnamesrv:namesrv -e "JAVA_OPTS=-Drocketmq.namesrv.addr=namesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" styletang/rocketmq-console-ng

docker run -e "JAVA_OPTS=-Drocketmq.namesrv.addr=192.168.0.103:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" -p 8090:8080 -t styletang/rocketmq-console-ng



./acme.sh --install-cert -d www.dcbuy.co.kr --key-file  /data1/certskey.pem --fullchain-file /data1/certs/cert.pem --reloadcmd  "service nginx force-reload"

certbot-auto certonly --webroot --email hz.allan.liu@gmail.com -w /data1/certs


#查看容器ip
docker inspect 909f641546ab | grep IPAddress


yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine \
                  docker-ce